<?php
!defined("EW_ROOT") && exit('No direct script access allowed');
/**
* Ecommerce Web Content Management System
* @copyright (c) 2011 ewcms team http://www.ewcms.org
* @license  GNU GENERAL PUBLIC LICENSE (GPLv3)
* @author iceweb
*/
class wsCore
{	
		
	function __construct()
	{
		if(DEBUG_MODE==0)
		{
			runTime::$time=runTime::getSecondTime();
			runTime::$memory=runTime::getNowMem();
		}
	}
	
	/**
	 * 启动路由解析
	 */
	public function start()
	{
		wsRoute::routePath();
		$this->dispenseRoute();
	}
	
	/**
	 * 分发路由
	 */
	private function dispenseRoute()
	{
		$wsPath=wsRoute::getPath();
		if($wsPath==false)
		{
			wsEcho::showMsg(wsLang::getLang('system_route_error'));
		}
		else 
		{
			$this->exeFun($wsPath[0],$wsPath[1]);
		}
	}
	
	/**
	 * 执行方法
	 * @param string $class
	 * @param string $fun
	 */
	private function exeFun($class,$fun)
	{
		$class=strtolower($class);
		$success=$class=='empty' ?false :TRUE;
		$class=ucfirst($class);
		$file=EW_ROOT.APP_PATH.'/controllers/'.$class.'Action.php';
		if(!file_exists($file))
		{
			$class="Empty";
			$fun='index';
		}
		if($success==FALSE || file_exists($file)==false)
		{
			wsEcho::showMsg(wsLang::getLang('system_error_contr_not_exits'));
		}
		require $file;
		$className=$class.'Action';
		$className=new $className;
		if(method_exists($className,$fun))
		{
			$className->$fun();
		}
		elseif (method_exists($className,'_empty'))
		{
			$className->_empty();
		}
		else 
		{
			wsEcho::showMsg(wsLang::getLang('system_fun_error').$fun);
		}
	}
}
